﻿

using System;
using System.Collections.Generic;
using System.Linq;
using Web.Models;
using Model.Core.DataBase;
using Web.Models.AnalysisData;
using Web.Models.CoreData;


namespace Web.BML.CoreData
{
    /// <summary>
    /// 用户船舶
    /// </summary>
    public class UserVesselOp
    {

        private static UserVesselOp instance;

        private UserVesselOp()
        {

        }
        /// <summary>
        /// 单例模式实例化
        /// </summary>
        /// <returns></returns>
        public static UserVesselOp GetInstance()
        {
            if (instance == null)
            {
                instance = new UserVesselOp();
            }
            return instance;
        }

        #region 查询
        /// <summary>
        ///    查询用户下的所有船
        /// </summary>
        /// <param name="userId">用户id</param>
        /// <returns></returns>
        public List<UserVessel> QueryUserVessel(String userId)
        {
            using (IDbContext db = ContainerFactory.OpenCoreConnect())
            {
                return db.Queryable<UserVessel>().Where(m => m.userId == userId).ToList();
            }
        }

        /// <summary>
        ///    查询用户船舶信息
        /// </summary>
        /// <param name="id">用户船舶id</param>
        /// <returns></returns>
        public UserVessel QueryUserVesselById(String id)
        {
            using (IDbContext db = ContainerFactory.OpenCoreConnect())
            {
                return db.Queryable<UserVessel>().FirstOrDefault(m => m.Id == id.ToString());
            }
        }

        /// <summary>
        /// 查询所有用户船舶
        /// </summary>
        /// <returns></returns>
        public List<UserVessel> QueryAllUserVessel()
        {
            using (IDbContext db = ContainerFactory.OpenCoreConnect())
            {
                return db.Queryable<UserVessel>().ToList();
            }
        }

        


        #endregion 查询

        /// <summary>
        /// 修改用户
        /// </summary>
        /// <param name="model"></param>
        public void ModifUserVessel(UserVessel model)
        {
            using (IDbContext db = ContainerFactory.OpenCoreConnect())
            {
                db.GetOperator<UserVessel>().Modify(model);
                db.SaveAllChange();
            }
        }

        /// <summary>
        /// 创建用户
        /// </summary>
        /// <param name="model"></param>
        public void CreateUserVessel(UserVessel model)
        {
            using (IDbContext db = ContainerFactory.OpenCoreConnect())
            {
                db.GetOperator<UserVessel>().Create(model);
                db.SaveAllChange();
            }
        }

        /// <summary>
        /// 删除用户
        /// </summary>
        /// <param name="model"></param>
        public void DeleteUserVessel(UserVessel model)
        {
            using (IDbContext db = ContainerFactory.OpenCoreConnect())
            {
                db.GetOperator<UserVessel>().Destroy(model);
                db.SaveAllChange();
            }
        }

        

    }


}

